package com.example.demo.service;

import com.example.demo.dao.UserDao;
import com.example.demo.enums.UserStatus;
import com.example.demo.model.User;
import com.example.demo.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@Slf4j
public class UserService {

    @Autowired
    UserDao userDao;

    public Boolean createUser(String name, String pwd) {
        User user = new User();
        user.setUsername(name);
        user.setEncryptPassword(PasswordUtil.encryptPassword(pwd, PasswordUtil.salt));
        user.setStatus(UserStatus.VALID.value());
        return Objects.equals(userDao.create(user), 1);
    }
}
